package com.schoolcardinfo.biz.impl;

import java.util.ArrayList;
import java.util.List;

import com.schoolcardinfo.beans.LoseInfo;
import com.schoolcardinfo.biz.ILoseInfoBiz;
import com.schoolcardinfo.dao.DBHelper;

public class LoseInfoBizImpl implements ILoseInfoBiz{
	private DBHelper db=new DBHelper();
	@Override
	public int addLostInfo(LoseInfo li) {
		String sql="insert into loseInfo values(null,?,?,?,default)";
		List<Object> params=new ArrayList<Object>();
		params.add(li.getLtime());
		params.add(li.getStudentId());
		params.add(li.getEtime());
		int result=db.update(sql, params);
		return result;
	}

	@Override
	public List<LoseInfo> selectLostInfo(int studentId, int lget) {
		String sql="";
		
		//查全部
		if(studentId==0 && lget==0){
			sql="select * from loseInfo";
		}
		//查单个学号的
		if(studentId!=0){
			sql="select * from loseInfo where studentId="+studentId;
		}
		//查询领取情况
		if(lget!=0){
			sql="select * from loseInfo where lget="+lget;
		}
		List<LoseInfo> list=db.find(sql, null, LoseInfo.class);
		if(list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	@Override
	public int updateLoseInfo(String studentId) {
		String sql="UPDATE loseInfo SET lget = 2 WHERE studentId in ('"+studentId+"')";
		int result=db.update(sql, null);
		return result;
	}
}
